<?php
/**
 * @name /lib/public/HTMLControls/Button.php
 * @author Michael Foss <webdesign@matatechconsulting.com>
 * @version 2008.09.06
 *
 * Button class library.
 */

ReqLib('/lib/public/HTMLControls/HTMLControl.php');

/**
 * Button class.
 *
 */
class Button extends HTMLControl {
  /**
   * The value for the control.
   *
   * @var string
   */
  var $Value;
  /**
   * The onclick event.
   *
   * @var string
   */
  var $OnClick;
  /**
   * The style of the wrapping container for the control.
   *
   * @var string
   */
  var $ContainerStyle;

  /**
   * Constructor.
   *
   * @param string $Id
   * @param string $Value
   */
  function Button($Id, $Value) {
    $this->HTMLControl($Id);
    $this->Value = $Value;
    $this->OnClick = '';
    $this->ContainerStyle = '';
  }

  /**
   * Gets the value currently assigned to the control.
   *
   * @return string
   */
  function GetValue() {
    return $this->Value;
  }

  /**
   * Sets the value of the control.
   *
   * @param string $Value
   */
  function SetValue($Value = '') {
    $this->Value = $Value;
  }

  /**
   * Prints the control; returns true on success.
   *
   * @return boolean
   */
  function Display() {
    if (!$this->Id)
      return false;
    if ($this->ContainerStyle)
      print('<div class="ButtonContainer" style="' . htmlspecialchars($this->ContainerStyle) . '">');
    else
      print('<div class="ButtonContainer">');
    print('<input type="button" id="' . htmlspecialchars($this->Id) . '" name="' . htmlspecialchars($this->Id) . '" value="' . htmlspecialchars($this->Value) . '" ' . ($this->OnClick ? 'onclick="' . htmlspecialchars($this->OnClick) . '" ' : '') . '/>');
    print('</div>');
    return true;
  }
}
